#include "key.h"

unsigned char key_get(void)
{
	static unsigned char befor,now=0;
	unsigned char key_num=0;
	if(HAL_GPIO_ReadPin(GPIOE,GPIO_PIN_7)==0)
	{
		key_num=1;
		return key_num;
	}
	if(HAL_GPIO_ReadPin(GPIOE,GPIO_PIN_8)==0)
	{
		key_num=2;
		return key_num;
	}
	if(HAL_GPIO_ReadPin(GPIOE,GPIO_PIN_9)==0)
	{
		key_num=3;
		return key_num;
	}
	if(HAL_GPIO_ReadPin(GPIOE,GPIO_PIN_10)==0)
	{
		key_num=4;
		return key_num;
	}

	return key_num;
}
unsigned char key_loop(void)
{
	static unsigned char befor,now,count;
	unsigned char keynum=0;
	befor=now;
	now=key_get();
	if(befor==now&&befor!=0){count++;}
	if(befor==1&&now==0)
	{
		count=0;keynum=1;
	}		
	if(befor==2&&now==0)
	{

		count=0;keynum=2;
	}
	
	if(befor==3&&now==0)
	{

		count=0;keynum=3;
	}
	if(befor==4&&now==0)
	{

		count=0;keynum=4;
	}
	return keynum;
}

